package org.msfj.admin.org.controller;

import org.msfj.admin.model.Role;
import org.msfj.admin.vo.RoleVo;
import org.msfj.admin.model.Role;
import org.msfj.admin.vo.RoleVo;
import org.msfj.admin.model.Role;
import org.msfj.admin.vo.RoleVo;
import org.msfj.admin.org.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.msfj.common.base.BaseController;
import org.msfj.common.model.CommonResult;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 系统角色信息controller
 * @Author: like
 * @Email: like@deyatong.com
 * @Date: 2017-08-10 17:30:20
 * @Version: 1.0
 * @Created in idea by autoCode
 */
@Api(value = "系统角色信息接口", tags = "系统角色信息接口")
@RestController
@RequestMapping("org/role")
public class RoleController extends BaseController{

    @Autowired
    private RoleService roleService;

    /**
     * 添加系统角色信息
     *
     * @param roleVo
     * @return CommonResult.ok(RoleVo)
     */
    @PostMapping("/add")
    @ResponseBody
    @ApiOperation(value = "添加系统角色信息",notes = "添加系统角色信息")
    @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query")
    public CommonResult addRole(RoleVo roleVo){
        Role role = roleService.saveOrEdit(roleVo);
        return CommonResult.ok(roleService.setOtherProperties(role));
    }

    /**
     * 修改系统角色信息
     *
     * @param roleVo
     * @return CommonResult.ok(RoleVo)
     */
    @PostMapping("/edit")
    @ResponseBody
    @ApiOperation(value = "修改系统角色信息",notes = "修改系统角色信息")
    @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query")
    public CommonResult editRole(RoleVo roleVo){
        Role role = roleService.saveOrEdit(roleVo);
        return CommonResult.ok(roleService.setOtherProperties(role));
    }

    /**
     * 逻辑删除系统角色信息
     *
     * @param roleVo
     * @return CommonResult.ok(RoleVo)
     */
    @PostMapping("/del")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统角色信息",notes = "逻辑删除系统角色信息")
    @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query")
    public CommonResult delRole(RoleVo roleVo){
        Role role = roleService.delById(roleVo);
        return CommonResult.ok(roleService.setOtherProperties(role));
    }

    /**
     * 逻辑删除系统用户信息
     * @param ids
     * @return CommonResult.ok()
     */
    @PostMapping("/dels")
    @ResponseBody
    @ApiOperation(value = "逻辑删除系统角色信息",notes = "逻辑删除系统角色信息")
    @ApiImplicitParam(value = "ids",name = "ids",dataType = "java.util.List",paramType = "query")
    public CommonResult delUsers(@RequestParam("ids[]") String[] ids){
        Role role = new Role();
        roleService.delAllByIds(ids, role);
        return CommonResult.ok();
    }

    /**
     * 真实删除系统角色信息
     *
     * @param roleVo
     * @return CommonResult.ok()
     */
    @PostMapping("/delete")
    @ResponseBody
    @ApiOperation(value = "真实删除系统角色信息",notes = "真实删除系统角色信息")
    @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query")
    public CommonResult deleteRole(RoleVo roleVo){
        roleService.trueDelById(roleVo);
        return CommonResult.ok();
    }

    /**
     * 根据id查找系统角色信息
     *
     * @param roleVo
     * @return CommonResult.ok(RoleVo)
     */
    @GetMapping("/get")
    @ResponseBody
    @ApiOperation(value = "根据id查找系统角色信息",notes = "根据id查找系统角色信息")
    @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query")
    public CommonResult getRole(RoleVo roleVo){
        Role role = roleService.getById(roleVo.getId());
        return CommonResult.ok(roleService.setOtherProperties(role));
    }

    /**
     * 根据翻页参数、搜索参数查找系统角色信息
     *
     * @param roleVo
     * @param page 当前第几页
     * @param rows 每页多少条记录
     * @return CommonResult.ok(PageInfo<RoleVo>)
     */
    @GetMapping("/list")
    @ResponseBody
    @ApiOperation(value = "根据翻页参数、搜索参数查找系统角色信息",notes = "根据翻页参数、搜索参数查找系统角色信息")
    @ApiImplicitParams({
        @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query"),
        @ApiImplicitParam(name = "page",value = "page",dataType = "Integer",paramType = "path"),
        @ApiImplicitParam(name = "rows",value = "rows",dataType = "Integer",paramType = "path")
    })
    public CommonResult findRoleList(RoleVo roleVo, Integer page, Integer rows){
        PageInfo<RoleVo> roleVoPageInfo = roleService.getByRole(roleVo,page,rows);
        return CommonResult.ok(roleVoPageInfo);
    }

    /**
     * 根据搜索参数查找所有系统角色信息
     *
     * @param roleVo
     * @return CommonResult.ok(List<RoleVo>)
     */
    @GetMapping("/getAll")
    @ResponseBody
    @ApiOperation(value = "根据搜索参数查找所有系统角色信息",notes = "根据搜索参数查找所有系统角色信息")
    @ApiImplicitParam(value = "roleVo",name = "roleVo",dataType = "org.msfj.admin.vo.RoleVo",paramType = "query")
    public CommonResult getAllRole(RoleVo roleVo){
        List<RoleVo> roleVoList = roleService.getAllRole(roleVo);
        return CommonResult.ok(roleVoList);
    }
}
